<!-- Element Plus Demo Page -->
<template>
  <div class="element-demo">
    <el-row class="header-row">
      <el-col :span="24">
        <div class="page-title">Element Plus 组件示例</div>
      </el-col>
    </el-row>

    <!-- 按钮示例 -->
    <el-card class="demo-card">
      <template #header>
        <div class="card-header">
          <span class="section-title">按钮组件</span>
        </div>
      </template>
      <el-row class="button-row">
        <el-button>默认按钮</el-button>
        <el-button type="primary">主要按钮</el-button>
        <el-button type="success">成功按钮</el-button>
        <el-button type="warning">警告按钮</el-button>
        <el-button type="danger">危险按钮</el-button>
      </el-row>
    </el-card>

    <!-- 表单示例 -->
    <el-card class="demo-card">
      <template #header>
        <div class="card-header">
          <span class="section-title">表单组件</span>
        </div>
      </template>
      <el-form :model="form" label-width="120px">
        <el-form-item label="用户名">
          <el-input v-model="form.name" placeholder="请输入用户名" />
        </el-form-item>
        <el-form-item label="活动区域">
          <el-select v-model="form.region" placeholder="请选择活动区域">
            <el-option label="区域一" value="shanghai" />
            <el-option label="区域二" value="beijing" />
          </el-select>
        </el-form-item>
        <el-form-item label="即时配送">
          <el-switch v-model="form.delivery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">提交</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <!-- 表格示例 -->
    <el-card class="demo-card">
      <template #header>
        <div class="card-header">
          <span class="section-title">表格组件</span>
        </div>
      </template>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="date" label="日期" />
        <el-table-column prop="name" label="姓名" />
        <el-table-column prop="address" label="地址" />
        <el-table-column label="操作">
          <template #default="scope">
            <el-button size="small" @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button
            >
            <el-button
              size="small"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <!-- 对话框示例 -->
    <el-card class="demo-card">
      <template #header>
        <div class="card-header">
          <span class="section-title">对话框组件</span>
        </div>
      </template>
      <el-button type="primary" @click="dialogVisible = true"
        >打开对话框</el-button
      >
      <el-dialog v-model="dialogVisible" title="提示" width="30%">
        <span>这是一个对话框的内容</span>
        <template #footer>
          <span class="dialog-footer">
            <el-button @click="dialogVisible = false">取消</el-button>
            <el-button type="primary" @click="dialogVisible = false"
              >确认</el-button
            >
          </span>
        </template>
      </el-dialog>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive } from "vue";

// 表单数据
const form = reactive({
  name: "",
  region: "",
  delivery: false,
});

// 表格数据
const tableData = [
  {
    date: "2024-01-01",
    name: "张三",
    address: "北京市朝阳区",
  },
  {
    date: "2024-01-02",
    name: "李四",
    address: "上海市浦东新区",
  },
];

// 对话框控制
const dialogVisible = ref(false);

// 方法
const onSubmit = () => {
  console.log("表单提交", form);
};

const handleEdit = (index: number, row: any) => {
  console.log("编辑", index, row);
};

const handleDelete = (index: number, row: any) => {
  console.log("删除", index, row);
};
</script>

<style scoped>
.element-demo {
  padding: 20px;
}

.header-row {
  margin-bottom: 16px;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  color: #111827;
  margin-bottom: 16px;
}

.demo-card {
  margin-bottom: 16px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.demo-card:hover {
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: #111827;
}

.button-row {
  margin-bottom: 16px;
}

.element-demo .el-button {
  margin-right: 12px;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* 响应式调整 */
@media (max-width: 640px) {
  .element-demo {
    padding: 16px;
  }

  .page-title {
    font-size: 20px;
  }

  .demo-card {
    margin-bottom: 12px;
  }

  .button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .element-demo .el-button {
    margin-right: 0;
  }
}
</style>
